package com.charlotte.gupao.study.springbootrabbitmqdemo.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;


/**
 * @author junjie.ding
 * @date 2020/10/30 1:13
 * @description TODO
 */
@Configuration
public class DelayQueueConfig {


    public final static String DELAYED_QUEUE_NAME = "DELAYED_QUEUE_NAME";

    public final static String DELAYED_EXCHANGE_NAME = "DELAYED_EXCHANGE_NAME";


    @Bean("delayedExchange")
    public CustomExchange delayedExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange(DELAYED_EXCHANGE_NAME, "x-delayed-message", true, false, args);
    }


    @Bean("delayedQueue")
    public Queue delayedQueue(){
        return new Queue(DELAYED_QUEUE_NAME, true);
    }

    @Bean
    public Binding bindingTopic2(@Qualifier("delayedQueue") Queue queue, @Qualifier("delayedExchange") CustomExchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(DELAYED_QUEUE_NAME).noargs();
    }
}
